package com.codeoss.framework.view.parser;

import org.springframework.stereotype.Service;

import com.codeoss.framework.view.component.Component;
import com.codeoss.framework.view.component.Icon;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

@Service
public class IconParser extends AbstractComponentParser {
	protected void setAttributes(IParseContext parseContext, ObjectNode objectNode, Component component) {
		super.setAttributes(parseContext, objectNode, component);
		Icon icon = (Icon) component;
		String iconClass = objectNode.get("iconClass").asText();
		icon.setIconClass(iconClass);
		ObjectNode propertyMapNode = (ObjectNode) objectNode.get("propertyMap");
		if (propertyMapNode != null) {
			JsonNode jsonNode = propertyMapNode.get("confirmMessage");
			if (jsonNode != null) {
				String confirmMessage = propertyMapNode.get("confirmMessage").asText();
				icon.setConfirmMessage(confirmMessage);
			}
		}
	}

	@Override
	protected Component createComponent(IParseContext parseContext, ObjectNode objectNode) {
		// TODO Auto-generated method stub
		return new Icon();
	}

}
